<template>
  <!--直接修改 meta -->
  <hr>
   <el-row :gutter="20" >
    <el-col :span="18">
      <el-slider v-model="formMeta.formMeta.columnsNumber" :min="1" :max="7" />
      <nf-form
        v-form-drag="formMeta"
        :model="model"
        :partModel="model2"
        v-bind="formMeta"
      >
      </nf-form>
    </el-col>
    <el-col :span="6">
      <div
        v-for="(item, key) in model"
        :key="key"
      >
        {{key}}：<span v-if="Array.isArray(item)">【
          <div v-for="item2 in item" :key="item2">
            &nbsp; &nbsp; {{item2}}
          </div>
          】
        </span>
        <span v-else>{{item}}</span>
      </div>
    </el-col>
  </el-row>
  <hr>
  <help-form-card
    :drawerInfo="drawerInfo"
    :meta="formMeta"
    :formDom="formDom"
  ></help-form-card>
  
</template>

<script lang="ts">
  import { defineComponent, reactive, ref } from 'vue'
  import { ElRow, ElCol, ElSlider } from 'element-plus'

  import { createModel, nfForm } from '@naturefw/ui-elp'
  import { helpFormCard } from '../../../lib/main'

  // 自定义指令
  import { _formDrag } from '@naturefw/ui-elp'

  import _formMeta from './form.json'

  export default defineComponent({
    name: 'nf-elp-form-page',
    directives: {
      formDrag: _formDrag
    },
    components: {
      ElRow, ElCol, ElSlider,
      nfForm,
      helpFormCard
    },
    props: {
    },
    setup(props, context) {

      const formMeta = reactive(_formMeta)
      // console.log('读取的 json：', formMeta)

      formMeta.formMeta.colOrder = [
        90,  101, 100, 103, 104, 105,
        110, 111,
        120, 121, 122, 123, 124
      ]

      const { itemMeta } = formMeta
      const { colOrder } = formMeta.formMeta
      const model2 = reactive({})

      // 根据 meta 创建表单的 model
      const model = createModel(itemMeta, colOrder)
      // console.log('model：', model)

      // 表单的对象
      const formDom = ref(null)
       

      return {
        formDom,
        formMeta,
        model2,
        model
      }
    }
  })
</script>